//
//  ZpVisitorLoginView.m
//  WeiBo_OC
//
//  Created by MacBook Pro on 16/5/26.
//  Copyright © 2016年 MacBook Pro. All rights reserved.
//

#import "ZpVisitorLoginView.h"

@interface ZpVisitorLoginView ()

@property (nonatomic, weak) UIButton *loginBtn;
@property (nonatomic, weak) UIButton *registerBtn;
@property (nonatomic, weak) UILabel  *contentLabel;
@property (nonatomic, weak) UIImageView *iconImageView;
@property (nonatomic, weak) UIImageView *circleImageView;
@property (nonatomic, weak) UIImageView *backImageView;
@end
@implementation ZpVisitorLoginView

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        self.backgroundColor = [UIColor colorWithWhite:0.95 alpha:1];
        
        
        UIButton *loginBtn = [[UIButton alloc] init];
        UIButton *registerBtn = [[UIButton alloc] init];
        UILabel *contentLabel = [[UILabel alloc] init];
        UIImageView *iconImageView = [[UIImageView alloc] init];
        UIImageView *circleImageView = [[UIImageView alloc] init];
        UIImageView *backImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"visitordiscover_feed_mask_smallicon" ]];
        
        [loginBtn addTarget:self action:@selector(loginView) forControlEvents:UIControlEventTouchDown];
        [registerBtn addTarget:self action:@selector(registerView) forControlEvents:UIControlEventTouchDown];
        
        self.iconImageView = iconImageView;
        self.contentLabel = contentLabel;
        self.loginBtn = loginBtn;
        self.registerBtn = registerBtn;
        self.circleImageView = circleImageView;
        self.backImageView = backImageView;
        
        [self addSubview:loginBtn];
        [self addSubview:registerBtn];
        [self addSubview:circleImageView];
        [self addSubview:backImageView];
        [self addSubview:contentLabel];
        [self addSubview:iconImageView];

        
        [self setUIContraint];
        
    }
    return self;
}

- (void)startAnimation{
    CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
    
    animation.toValue = @(2 * M_PI);
    animation.duration = 15;
    animation.repeatCount = MAXFLOAT;
    animation.removedOnCompletion = NO;
    
    [self.circleImageView.layer addAnimation:animation forKey:nil];
    
}

- (void)setUISizeWithImageName:(NSString *)imageName andContentLabel:(NSString *)content{
    
    // 登录注册按钮
    [self.loginBtn setTitle:@"登录" forState:UIControlStateNormal];
    [self.registerBtn setTitle:@"注册" forState:UIControlStateNormal];
    
    [self.loginBtn setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
    [self.registerBtn setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
    
    [self.loginBtn setBackgroundImage:[UIImage imageNamed:@"common_button_white_disable"] forState:UIControlStateNormal];
    [self.registerBtn setBackgroundImage:[UIImage imageNamed:@"common_button_white_disable"] forState:UIControlStateNormal];
    
    self.contentLabel.text = content;
    self.contentLabel.textAlignment = NSTextAlignmentCenter;
    self.contentLabel.font = [UIFont systemFontOfSize:12];
    self.contentLabel.numberOfLines = 0;
    
    self.iconImageView.image =[UIImage imageNamed:imageName];
    [self.iconImageView sizeToFit];
    self.circleImageView.image = [UIImage imageNamed:@"visitordiscover_feed_image_smallicon"];
    [self.circleImageView sizeToFit];
    
}

- (void)setUIContraint{
    
    
    [self.circleImageView makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.centerY.equalTo(self).offset(-80);
    }];
    
    [self.backImageView makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self.circleImageView);
    }];
    
    [self.iconImageView makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self.circleImageView);
    }];
    
    [self.contentLabel makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(20);
        make.right.equalTo(self).offset(-20);
        make.top.equalTo(self.circleImageView.bottom).offset(16);
        make.height.equalTo(40);
    }];
    
    [self.loginBtn makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(40);
        make.top.equalTo(self.contentLabel.bottom).offset(16);
        make.width.equalTo(100);
        make.height.equalTo(50);
    }];
    
    [self.registerBtn makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self).offset(-40);
        make.top.equalTo(self.contentLabel.bottom).offset(16);
        make.width.equalTo(100);
        make.height.equalTo(50);
    }];
//    [self.contentLabel makeCOn]
    
/*
    1.item    需要添加约束的对象
    2.attribute  需要添加的约束的属性
    3.relatedBy   参照的方式 一般使用 精准约束 Equal
    4.toItem       参照的视图  一般参照 父视图 或者 兄弟视图
    5.attribute    参照布局的属性
    6.multiplier   乘积系数 一般使用 1  但是不能够 使用 0
    7.constant     尺寸: 设置大小  坐标: 偏移  一般使用

    self.iconImageView.translatesAutoresizingMaskIntoConstraints = NO;
    NSLayoutConstraint *iconConstraint_CenterX = [NSLayoutConstraint constraintWithItem:self.iconImageView attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeCenterX multiplier:1 constant:0];
    NSLayoutConstraint *iconConstraint_CenterY = [NSLayoutConstraint constraintWithItem:self.iconImageView attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeCenterY multiplier:1 constant:0];
    [self addConstraint:iconConstraint_CenterX];
    [self addConstraint:iconConstraint_CenterY];
 */
   
}

- (void)hiddenCircleImage:(BOOL)isHome{
    if (isHome) {
        self.circleImageView.hidden = NO;
    }else{
        self.circleImageView.hidden = YES;
    }
}

- (void)loginView{
    [self.delegate willUserLogin];
    [SVProgressHUD show];
}

- (void)registerView{
    [self.delegate willUserRegister];
}
@end
